package com.lagou.service.impl;

import com.lagou.base.StatusCode;
import com.lagou.dao.CourseContentDao;
import com.lagou.dao.impl.CourseContentDaoImpl;
import com.lagou.poji.Course;
import com.lagou.poji.Course_Section;
import com.lagou.service.CourseContentService;
import com.lagou.service.CourseService;
import com.lagou.utils.DateUtils;

import java.util.List;

/*
* 课程内容管理Service实现类
*
* */
public class CourseContentImpl implements CourseContentService {
    CourseContentDao contentDao = new CourseContentDaoImpl();
    @Override
    public List<Course_Section> findSectionAndLessonByCourseId(int courseId) {
        List<Course_Section> sections =contentDao.findSectionAndLessonByCourseId(courseId);
        return sections;
    }

    @Override
    public Course findCourseByCourseId(int courseId) {
        Course course = contentDao.findCourseByCourseId(courseId);

        return course;

    }

    @Override
    public String saveSection(Course_Section section) {

        section.setStatus(2);

        String dateFormart = DateUtils.getDateFormart();

        section.setCreate_time(dateFormart);

        section.setUpdate_time(dateFormart);

        int i = contentDao.saveSection(section);

        if(i>0){
            String s = StatusCode.SUCCESS.toString();
            return s;


        }else {
            String s = StatusCode.FAIL.toString();
            return s;

        }


    }

    @Override
    public String updateSection(Course_Section section) {
        String date = DateUtils.getDateFormart();
        section.setUpdate_time(date);

        int i = contentDao.updateSection(section);

        if(i>0){
            String s = StatusCode.SUCCESS.toString();
            return s;

        }else {
            String s = StatusCode.FAIL.toString();
            return s;

        }


    }

    @Override
    public String updateSectionStatus(int id, int status) {
        int i = contentDao.updateSectionStatus(id,status);
        if(i > 0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else{
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }
}
